<template>
  <el-dropdown>
    <span class="el-dropdown-link">
      <el-avatar
        :size="30"
        src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
      ></el-avatar>
      <span class="userName">{{ name }}</span>
    </span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item @click="handleExitClick">
          <el-icon>
            <CircleClose />
          </el-icon>
          退出登录
        </el-dropdown-item>
        <el-dropdown-item divided>
          <el-icon>
            <Avatar />
          </el-icon>
          用户信息
        </el-dropdown-item>
        <el-dropdown-item>
          <el-icon>
            <Menu />
          </el-icon>
          系统管理
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import { useStore } from '@/store'
import localCache from 'utils/cache'
import { useRouter } from 'vue-router'
export default defineComponent({
  setup() {
    // store
    const store = useStore()
    const name = computed(() => store.state.login.userInfo.name)

    // router
    const router = useRouter()
    const handleExitClick = () => {
      localCache.deleteCache('token')
      router.push('/login')
    }

    return {
      name,
      handleExitClick
    }
  }
})
</script>

<style lang="scss" scoped>
.userName {
  margin-left: 5px;
}
.el-dropdown-link {
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
.el-icon-arrow-down {
  font-size: 16px;
}
.el-icon {
  margin: 0 5px 0 0 !important;
}
</style>
